﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ET;
namespace Marx
{

    [ObjectSystem]
    public class PlayerSessionMonitorDestroySystem : DestroySystem<PlayerSessionMonitor>
    {
        public override void Destroy(PlayerSessionMonitor self)
        {
            self.OnDestroy();
        }
    }

    public class PlayerSessionMonitor : Entity, IAwake, IDestroy
    {
        public void OnDestroy()
        {
            var session = GetParent<Session>();
            if(session == null)
            {
                return;
            }

            if(session.Error == ET.ErrorCore.ERR_SessionSendOrRecvTimeout)
            {
                Game.EventSystem.Publish(new EventType.LostConnection() { Player = Player.Instance });
            }
            else
            {
                Game.EventSystem.Publish(new EventType.FatalAndLogout());
            }
        }
    }
}
